package com.mitake.nick.util;

import java.util.Calendar;
import java.util.Locale;

import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.factory.support.PropertiesBeanDefinitionReader;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;
import org.springframework.core.io.ClassPathResource;

import com.mitake.nick.bean.HelloBean;

public class SpringDemo {

	public static void main(String[] args) {
		ApplicationContext context = new FileSystemXmlApplicationContext("/config/beans-config.xml");
		
		
		HelloBean hello = (HelloBean) context.getBean("helloBean");
		System.out.println(hello.getName());
		System.out.println(hello.getAge());
		
		System.out.println(hello.getArray()[0] +", "+ hello.getArray()[1]);
		System.out.println(hello.getList());
		System.out.println(hello.getMap().get("key1") +", "+ hello.getMap().get("key2"));
		
		
		//Use properties
//		BeanDefinitionRegistry reg = new DefaultListableBeanFactory(); 
//        PropertiesBeanDefinitionReader reader = new PropertiesBeanDefinitionReader(reg); 
//        reader.loadBeanDefinitions(new ClassPathResource("/resources/beans-config.properties")); 
//        
//        BeanFactory factory = (BeanFactory) reg; 
//        HelloBean helloProperties = (HelloBean) factory.getBean("helloBean"); 
//        System.out.println(helloProperties.getName()); 
		
		//i18n
//		context = new ClassPathXmlApplicationContext("beans-config.xml");
//		Object[] arguments = new Object[] {"Nick", Calendar.getInstance().getTime()}; 
	    System.out.println(context.getMessage("label.firstname", null, Locale.US)); 
	    System.out.println(context.getMessage("label.firstname", null, Locale.TAIWAN));
	}

}
